/*实力评级*/
EMui.vmGrade=(function(){
    var views={};

    //战队
    views.team=[new LeafView({
        id:"#teamList",
        state:{isShow:true},
        elBox:$("#teamList>ul")[1],
        isLoadMore:false,
        param:{
            url:EMui.urls.domain+EMui.urls.gradeTeamList,
            data:{ _start:0, _limit:50}
        }
    })];



    //选手
    var vm1=new LeafView({
        id:"#playerType",
        param:{
            url:EMui.urls.domain+EMui.urls.gradePlayerType,
            data:{ _start:0, _limit:100 }
        },
        isLoadMore:false,
        vm:new Vue({
            el:$("#playerType  select")[0] ,
            data:{list:[]},
            watch:{
                'list':function () {
                    vm2.param.data.typeId=$(this.$el).find('option:selected').val();
                    vm2.fillData();
                }
            },
            methods: {
                getList: function (event) {
                    vm2.param.data.typeId=$(this.$el).find('option:selected').val();
                    vm2.fillData();
                }
            }
        })
    })
    var vm2= new LeafView({
            id:"#playerList",
            state:{isShow:false},
            elBox:$("#playerList>ul")[1],
            isLoadMore:false,
            param:{
                url:EMui.urls.domain+EMui.urls.gradePlayerList,
                data:{ _start:0, _limit:50,typeId:0}
            }
        });


    //选手tab中的所有视图
    views.player= [vm1,vm2 ];



    //切换标签
    var tab=$("#gradeType"),lis=$("li",tab),viewName,curView=null;
    lis.on("changetab",function(){
        viewName=$(this).data("view");
        curView=views[viewName];

        for(var arr in views){
            if(curView==views[arr]){
                var cur=views[arr][0];
                cur.fillData();
                $.each(views[arr],function(n,view){
                    view.state.isShow=true;
                });
            }else{
                $.each(views[arr],function(n,view){
                    view.state.isShow=false;
                });
            }

        }
    });




    return{
        init:function(){
            for(var arr in views){
                $.each(views[arr],function(n,view){
                    if(view.state.isShow){
                        view.fillData();
                    }
                });
            }
        },

        reloadData:function(){
            console.log('reloadData');
            for(var arr in views){
                $.each(views[arr],function(n,view){
                    view.param.data={_start:view.oldParamPage._start,_limit:view.oldParamPage._limit};
                    view.state.isNoneData=false;
                    view.vm.list=[];
                    if( view.vm.typeId){
                        view.vm.typeId=0
                    }
                    if(view.state.isShow){
                        if(view.isLoadMore){view.offLoadMore();}
                        view.fillData();
                    }
                });
            }


        }
    }
})();



